﻿using System;
using SaleManagement.Web.App_Code;
using SaleManagement.Domains;
using SaleManagement.Services;
using DevExpress.Web.ASPxGridView;
using System.Web.UI.HtmlControls;

namespace SaleManagement.Web.Pages
{
  public partial class WarningInventory : BasePage
  {
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsCallback && !IsPostBack)
      {
        LoadAlertInventory();
      }

      if (gvProduct.IsCallback)
      {
        LoadAlertInventory();
      }
    }
    #endregion

    #region Methods
    private void LoadAlertInventory()
    {
      gvProduct.DataSource = new ProductService().GetAlertInventory();
      gvProduct.DataBind();
      ApplyProductMasterLayout();
    }

    private void ApplyProductMasterLayout()
    {
      gvProduct.BeginUpdate();
      try
      {
        gvProduct.ClearSort();
        gvProduct.GroupBy((DevExpress.Web.ASPxGridView.GridViewColumn)gvProduct.Columns["Id"]);
      }
      catch (Exception ex)
      {
        WriteLog("InventoryReport.aspx::Apply Master Layout", ex);
      }
      finally
      {
        gvProduct.EndUpdate();
      }
      gvProduct.ExpandAll();
    }

    #endregion
  }
}
